﻿using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using TechMadeira.Data;

namespace TechMadeira.App.UITypeEditors
{
    public class ClientEditor : UITypeEditor
    {
        public override UITypeEditorEditStyle GetEditStyle( ITypeDescriptorContext context )
        {
            return UITypeEditorEditStyle.Modal;
        }

        public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value )
        {
            var service = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;

            var client = value as IClient;
            if ( service != null )
            {            
                using ( var dialog = new ClientEditorForm())
                {
                    dialog.SelectedClient = client;
                    if ( service.ShowDialog( dialog ) == DialogResult.OK)
                    {
                        client = dialog.SelectedClient;
                    }
                }
            }
            return client;
        }

    }
}
